#include<bits/stdc++.h>
#define int long long
#define N 10000005
using namespace std;
int n,k;
int a[N];
int f[N],h[N];
int ans;
int len,s[N];
const int mod=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
void sub(){
	for(int i=1;i<=n;i++){
		int mx=a[i];
		f[i]=1e18;
		for(int j=i-1;j>=max(0ll,i-k);j--){
			f[i]=min(f[i],f[j]+mx);
			mx=max(mx,a[j]);
		}
		ans=(ans+f[i]%mod*h[n-i]%mod)%mod;
	}
	printf("%lld",ans);
}
#define ls (x<<1)
#define rs ((x<<1)|1)
#define mid ((l+r)>>1)
int t[N<<2],lazy[N<<2];
void pushup(int x){
	t[x]=min(t[ls],t[rs]);
}
void down(int x,int k){
	t[x]+=k;
	lazy[x]+=k;
}
void pushdown(int x){
	if(!lazy[x]) return;
	down(ls,lazy[x]);
	down(rs,lazy[x]);
	lazy[x]=0;
}
void update(int x,int l,int r,int L,int R,int k){
	if(L>R) return;
	if(L<=l&&r<=R){
		down(x,k);
		return;
	}
	pushdown(x);
	if(L<=mid) update(ls,l,mid,L,R,k);
	if(R>mid) update(rs,mid+1,r,L,R,k);
	pushup(x);
}
int query(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R) return t[x];
	pushdown(x);
	int res=1e18;
	if(L<=mid) res=min(res,query(ls,l,mid,L,R));
	if(R>mid) res=min(res,query(rs,mid+1,r,L,R));
	return res;
}
signed main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	n=read();k=read();
	for(int i=1;i<=n;i++) a[i]=read();
	h[0]=1;
	for(int i=1;i<=n;i++) h[i]=h[i-1]*23%mod;
	if(n<=2000){sub();return 0;}
	s[++len]=0;
	s[0]=0;
	update(1,0,n,0,0,a[1]);
	for(int i=1;i<=n;i++){
		while(len&&a[s[len]]<=a[i]) update(1,0,n,s[len-1],s[len]-1,a[i]-a[s[len]]),len--;
		s[++len]=i;
		f[i]=query(1,0,n,max(0ll,i-k),i-1);
		update(1,0,n,i,i,f[i]+a[i+1]);
		ans=(ans+f[i]%mod*h[n-i]%mod)%mod;
	}
	printf("%lld",ans);
	return 0;
}